//
//  IncubationSpaceMessageController.m
//  BigToBig
//
//  Created by yi liu on 16/8/8.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "IncubationSpaceMessageController.h"
#import "IncubationSpaceMessageView.h"

#import "PublishMessageViewController.h"
#import "DetailInfoCell.h"
#import "IncubationSpacePublishCell.h"
#import "IncubationSpacePrincipleCell.h"

@interface IncubationSpaceMessageController ()
<
    UITableViewDelegate,
    UITableViewDataSource,
    IncubationSpacePublishCellDelegate
>
@property (nonatomic ,strong)IncubationSpaceMessageView *incubationSpaceMassageView;
@property (nonatomic , strong)UITableView *mainTableView;
@property (nonatomic , strong)NSArray *sectionTitleArray;
@property (nonatomic , strong)NSString *describeStr;
@property (nonatomic , strong)NSArray *principleInfoKeyArray;
@end

@implementation IncubationSpaceMessageController

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    [self createData];
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"孵化空间信息";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    [self createView];

}
#pragma mark 创建数据
- (void)createData{
    self.describeStr = @"自我介绍是向别人展示你自己的一个重要手段, 自我介绍好不好, 甚至直接关系到你给别人的第一印象的好坏及以后交往的顺利与否. 同时, 也是认识自我的手段. 自我介绍是每一个职场中人都必然要经历的一件事情, 只不过.";

    self.sectionTitleArray = @[@"公司描述",@"发布信息",@"负责人信息"];
    self.principleInfoKeyArray = @[@"姓名",@"电话",@"主页",@"说明"];
}

#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
}

- (void)backController:(UIButton *)button{
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 创建View
- (void)createView{
    self.incubationSpaceMassageView = [[IncubationSpaceMessageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
    self.incubationSpaceMassageView.nameLabel.text = @"北京云真网络技术服务有限公司";
    self.incubationSpaceMassageView.capitalLabel.text = [NSString stringWithFormat:@"固定资产 : 12万"];
    self.incubationSpaceMassageView.bussinessLabel.text = [NSString stringWithFormat:@"主营业务 : 的多层次的"];
    self.incubationSpaceMassageView.backgroundColor = [UIColor whiteColor];
    self.incubationSpaceMassageView.headImageView.image = [UIImage imageNamed:@"touxiang"];
    self.incubationSpaceMassageView.groupLabel.text = @"已认证公司";
    // 主tableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];
    self.mainTableView.tableHeaderView = self.incubationSpaceMassageView;
    self.mainTableView.tableHeaderView.height = self.incubationSpaceMassageView.height;
    [self.view addSubview:_mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.mainTableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:NSStringFromClass([DetailInfoCell class])];
    [self.mainTableView registerClass:[IncubationSpacePublishCell class] forCellReuseIdentifier:NSStringFromClass([IncubationSpacePublishCell class])];
    [self.mainTableView registerClass:[IncubationSpacePrincipleCell class] forCellReuseIdentifier:NSStringFromClass([IncubationSpacePrincipleCell class])];
    self.mainTableView.tableFooterView = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
    self.mainTableView.sectionHeaderHeight = 40;
    self.mainTableView.sectionFooterHeight = 0;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *sectionHeaderLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
    sectionHeaderLabel.text = self.sectionTitleArray[section];
    sectionHeaderLabel.textAlignment = NSTextAlignmentLeft;
    return sectionHeaderLabel;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        // 计算文字的高度
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
        // 根据文本的内容和文本的字体进行计算高度
        // 参数一:告诉系统,文本显示的最大范围
        CGFloat width = (self.view.frame.size.width - 40);
        CGRect rect = [self.describeStr boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        // 然后把图片的高和文本的高作为返回值返回
        return rect.size.height + 20;

    }
    else if (indexPath.section == 1){
        return 100;
    }
    else{
        return 70;
    }
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    else if (section == 1){
        return 2;
    }
    else{
        return 4;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailInfoCell class]) forIndexPath:indexPath];
        cell.infoLabel.text = self.describeStr;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if (indexPath.section == 1){
        IncubationSpacePublishCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([IncubationSpacePublishCell class]) forIndexPath:indexPath];
        cell.publishCellDelegate = self;
        cell.titleLabel.text = @"打印复印传真, 海报制作";
        cell.describeLabel.text = @"本人从事20余年打印复印传真, 海报制作工作......";
        cell.positionLabel.text = @"北京";
        cell.phoneNumberLabel.text = @"13240001617";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
        
    }
    else{
        IncubationSpacePrincipleCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([IncubationSpacePrincipleCell class]) forIndexPath:indexPath];
        cell.principleKeyLabel.text = self.principleInfoKeyArray[indexPath.row];
        cell.principleValueLabel.text = @"请填写";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
#pragma mark publish Cell  代理方法
- (void)pushToPublishMessageViewControllerWithModel:(id)model{
    PublishMessageViewController *publishMessageVC = [[PublishMessageViewController alloc] init];
    [self.navigationController pushViewController:publishMessageVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
